module NivelesHelper
  def button_to_add_fields(name, f, association)
    if name =="Agregar"
      new_object = f.object.class.reflect_on_association(association).klass.new
      fields =f.simple_fields_for(association,new_object,:child_index => "new_#{association}") do |builder|
        render(association.to_s.singularize, :f => builder )
      end
      button_to_function(name,h("agregarCampos(this,'#{association}','#{escape_javascript(fields)}')"),html_options={:id=>'add_fields'})
    else
      new_object = f.object.class.reflect_on_association(association).klass.new
      new_object.build_categoria
      fields =f.simple_fields_for(association,new_object,:child_index => "new_#{association}") do |builder|
        render("nueva_"+association.to_s.singularize, :f => builder )
      end
      button_to_function(name,h("crearNuevaCategoria(this,'#{association}','#{escape_javascript(fields)}')"))
    end
  end
end